package org.csu.mypetstore.persistence;

import java.sql.*;

public class DBUtil {
    private static String DRIVER = "com.mysql.cj.jdbc.Driver";
    private static String DATABASE = "jdbc:mysql://localhost:3306/petstore?serverTimezone=GMT&useSSL=false&allowPublicKeyRetrieval=true";
    private static String USERNAME = "jojo";
    private static String PASSWORD = "1234";

    public static Connection getConnection() throws Exception
    {
        Connection connection = null;
        try
        {
            Class.forName(DRIVER);
            connection = DriverManager.getConnection(DATABASE,USERNAME,PASSWORD);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return  connection;
    }

    public static void closeStatement(Statement statement) throws Exception
    {
        statement.close();
    }

    public static void closePreparedStatement(PreparedStatement preparedStatement)throws Exception
    {
        preparedStatement.close();
    }

    public static void closeResultSet(ResultSet resultSet)throws  Exception
    {
        resultSet.close();
    }

    public static void closeConnection(Connection connection)throws Exception
    {
        connection.close();
    }

//    public static void main(String[] args) throws Exception {
//        Connection connection = DBUtil.getConnection();
//        System.out.println(connection);
//    }

}
